package com.socket.controller;

import com.socket.service.WebSocketService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * socket控制器
 *
 * @author ww
 * @date 2018/7/5
 */
@RestController
@RequestMapping(value = "/socket")
public class WebSocketController {

    //推送数据接口
    @GetMapping("/push/{user}")
    public String pushToWeb(@PathVariable String user, String message) {
        try {
            Boolean success = WebSocketService.sendInfo(message, user);
            if (!success){
                return user + " error connect!";
            }
        } catch (IOException e) {
            e.printStackTrace();
            return "error";
        }
        return "sent to" + user + " massage success!";
    }
}
